{% extends "exam_system/base.html" %}

{% block content %}
<div class="container mt-4">
    <h2>可报名考试</h2>

    {% if messages %}
    <div class="messages">
        {% for message in messages %}
        <div class="alert alert-{{ message.tags }}">
            {{ message }}
        </div>
        {% endfor %}
    </div>
    {% endif %}

    {% if exam_rooms %}
    <div class="row">
        {% for exam_room in exam_rooms %}
        <div class="col-md-6 mb-4">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">{{ exam_room.name }}</h5>
                </div>
                <div class="card-body">
                    <p><strong>考试类型：</strong>{{ exam_room.exam_type }}</p>
                    <p><strong>考试科目：</strong>
                        {{ exam_room.subject_1.name }}
                        {% if exam_room.subject_2 %}
                        + {{ exam_room.subject_2.name }}
                        {% endif %}
                        {% if exam_room.subject_3 %}
                        + {{ exam_room.subject_3.name }}
                        {% endif %}
                    </p>
                    <p><strong>开始时间：</strong>{{ exam_room.start_time|date:"Y-m-d H:i" }}</p>
                    <p><strong>考试时长：</strong>{{ exam_room.duration }} 分钟</p>
                    <p><strong>总分：</strong>{{ exam_room.total_score }} 分</p>
                    <p><strong>题目数量：</strong></p>
                    <ul>
                        {% if exam_room.single_choice_count > 0 %}
                        <li>单选题：{{ exam_room.single_choice_count }}道（每题{{ exam_room.single_choice_score }}分）</li>
                        {% endif %}
                        {% if exam_room.multiple_choice_count > 0 %}
                        <li>多选题：{{ exam_room.multiple_choice_count }}道（每题{{ exam_room.multiple_choice_score }}分）</li>
                        {% endif %}
                        {% if exam_room.judgment_count > 0 %}
                        <li>判断题：{{ exam_room.judgment_count }}道（每题{{ exam_room.judgment_score }}分）</li>
                        {% endif %}
                    </ul>

                    {% if exam_room.is_registered %}
                    <button class="btn btn-secondary" disabled>已报名</button>
                    {% else %}
                    <form method="post" action="{% url 'exam_system:register_exam' exam_room.id %}" style="display: inline;">
                        {% csrf_token %}
                        <button type="submit" class="btn btn-primary">立即报名</button>
                    </form>
                    {% endif %}
                </div>
            </div>
        </div>
        {% endfor %}
    </div>
    {% else %}
    <div class="alert alert-info">
        目前没有可以报名的考试。
    </div>
    {% endif %}
</div>
{% endblock %}